package com.ruoyi.equipment.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.equipment.domain.TEquipmentLog;
import com.ruoyi.equipment.domain.UserHint;
import com.ruoyi.equipment.mapper.TEquipmentLogMapper;
import com.ruoyi.equipment.mapper.UserHintMapper;
import com.ruoyi.equipment.service.UserHintService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserHintServiceImpl implements UserHintService {


    @Autowired
    private UserHintMapper userHintMapper;

    @Autowired
    private TEquipmentLogMapper tEquipmentLogMapper;

    @Override
    public UserHint getUserHint(Long userId) {
        UserHint userHint = userHintMapper.selectUserHint(userId);
        //如果 userHint 为空  重新添加
        if (userHint ==null ){
            userHint=new UserHint();
            userHint.setUserId(userId);
            userHint.setHint(0);
            userHintMapper.insertUserHint(userHint);
        }
        return userHint;
    }

    @Override
    public void updateUserHint(Long userId) {
       int count= userHintMapper.updateUserHint(userId);
       if (count!=1){
           throw new RuntimeException("更新信息失败,请联系管理员");
       }
    }

    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    public int selectTEquipmentLogDeptByTime(TEquipmentLog tEquipmentLog) {
       int count= tEquipmentLogMapper.selectTEquipmentLogDeptByTime(tEquipmentLog);
       return count;
    }
}
